package com.xms.sdk.api.controller;

import com.xms.core.exception.XmsException;
import com.xms.sdk.api.model.SharedModel;
import com.xms.sdk.service.IDataSharer;
import com.xms.utils.UUIDUtil;
import com.xms.web.framework.controller.ApiBaseController;
import com.xms.web.framework.model.JsonResultObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * DataSharerController
 * </p>
 *
 * @author migo
 * @since 2021/10/10
 */
@RestController
@RequestMapping("{org}/api/data")
public class DataSharerController extends ApiBaseController {
    private IDataSharer _dataSharer;
    @Autowired
    public void DataSharerController(IDataSharer dataSharer) {
        _dataSharer = dataSharer;
    }

    @ApiOperation("共享记录")
    @PostMapping("share")
    public JsonResultObject share(@RequestBody SharedModel model) throws XmsException {
        if (model == null || UUIDUtil.isEmpty(model.entityId) || UUIDUtil.isEmpty(model.objectId))
        {
            return JNotSpecifiedParams("entityid", "objectid");
        }
        _dataSharer.share(model.entityId, model.objectId, model.principals);
        return JOk("共享成功");
    }
}
